<?php

namespace app\admin\builder;
class Table extends Base
{

    private $_data = [];

    public function setTitle($title)
    {
        $this->_data['seo_title'] = $title;
        return $this;
    }


    public function dataSource($data, $table)
    {
        $this->_data['table'] = $table;
        $this->_data['data'] = $data;
        return $this;
    }


    public function field($name, $title = '', $type = 'text')
    {
        $this->_data['field'][] = ['type' => $type, 'field' => $name, 'title' => $title ?: $name];
        return $this;
    }

    public function fieldStatus($name, $title = '')
    {
        return $this->field($name, $title, 'status');
    }

    public function fieldHtml($name, $title = '')
    {
        return $this->field($name, $title, 'html');
    }

    public function action($text = '', $extra = [])
    {
        $this->_data['action'][] = ['text' => $text, 'extra' => $extra];
        return $this;
    }

    public function button($text = '', $extra = [])
    {
        $this->_data['button'][] = ['text' => $text, 'extra' => $extra];
        return $this;
    }

    public function loadJs($path = [])
    {
        if (is_string($path)) {
            $path = [$path];
        }
        foreach ($path as $v) {
            $this->_data['js'][] = $v;
        }

        return $this;
    }

    public function loadCss($path = [])
    {
        if (is_string($path)) {
            $path = [$path];
        }
        foreach ($path as $v) {
            $this->_data['css'][] = $v;
        }

        return $this;
    }


    public function show()
    {
        if (empty($this->_data['data'])) {


        }

        $this->assign($this->_data);
        return view(dirname(dirname(__FILE__)) . '/builder/view/table.html');
    }


}
